package com.huang.lock;


import java.util.concurrent.atomic.AtomicReference;

//自旋锁
public class spinLockDemo {
    AtomicReference<Thread> atomicReference=new AtomicReference<>();
    //枷锁
    public void  myLock(){
        Thread thread = Thread.currentThread();
        System.out.println(Thread.currentThread().getName()+"....mylock");
        //自旋锁
        while (!atomicReference.compareAndSet(null, thread)) {
            System.out.println("自旋了");
        }
    }

    //解锁
    public void  myUnLock(){
        Thread thread = Thread.currentThread();
        System.out.println(Thread.currentThread().getName()+"....myUnLock");
        //解锁
        atomicReference.compareAndSet(thread, null);


    }



}
